package com.bocai.freeman.view.activitys;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseActivity;
import com.bocai.freeman.utils.ToolbarHelper;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by win7 on 2016/5/26.
 */
public class WhoCanSeeActivity extends BaseActivity {
    @Bind(R.id.img_open)
    ImageView imgOpen;
    @Bind(R.id.rl_open)
    RelativeLayout rlOpen;
    @Bind(R.id.img_perfect_light)
    ImageView imgPerfectLight;
    @Bind(R.id.rl_perfect_light)
    RelativeLayout rlPerfectLight;
    @Bind(R.id.img_private)
    ImageView imgPrivate;
    @Bind(R.id.rl_private)
    RelativeLayout rlPrivate;


    private ImageView oldImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_who_can_see);
        ButterKnife.bind(this);
        ToolbarHelper.setup(this, getString(R.string.str_who_can_see), R.mipmap.left_return, R.menu.menu_compelet, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        }, new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return false;
            }
        });

        initEvent();
    }

    @Override
    protected void initEvent() {
        oldImageView = imgOpen;
        click(rlOpen).subscribe(o -> {
            if (!oldImageView.equals(imgOpen)) {
                oldImageView.setVisibility(View.INVISIBLE);
                if (imgOpen.getVisibility() == View.INVISIBLE)
                    imgOpen.setVisibility(View.VISIBLE);
                oldImageView = imgOpen;
            }
        });
        click(rlPerfectLight).subscribe(o -> {
            if (!oldImageView.equals(imgPerfectLight)) {
                oldImageView.setVisibility(View.INVISIBLE);
                imgPerfectLight.setVisibility(View.VISIBLE);
                oldImageView = imgPerfectLight;
            }
        });
        click(rlPrivate).subscribe(o -> {
            if (!oldImageView.equals(imgPrivate)) {
                oldImageView.setVisibility(View.INVISIBLE);
                imgPrivate.setVisibility(View.VISIBLE);
                oldImageView = imgPrivate;
            }
        });
    }
}
